package me.bincker.formwork.web.modules.system.entity

import com.fasterxml.jackson.annotation.JsonIgnore
import me.bincker.formwork.web.core.entity.BaseEntity
import me.bincker.formwork.web.core.entity.Nameable
import me.bincker.formwork.web.core.validated.ValidAdd
import me.bincker.formwork.web.core.validated.ValidPut
import javax.persistence.*
import javax.validation.constraints.NotEmpty
import javax.validation.constraints.NotNull

@Entity
class Menu: BaseEntity(), Nameable {
    @NotEmpty(groups = [ValidAdd::class, ValidPut::class])
    override var name: String? = null

    var url: String? = null

    var icon: String? = null

    @NotNull(groups = [ValidAdd::class, ValidPut::class])
    var hidden: Boolean? = null

    @ManyToOne
    var parent: Menu? = null

    @JsonIgnore
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "parent")
    var children: MutableList<Menu>? = null

    @NotNull(groups = [ValidAdd::class, ValidPut::class])
    var type: Type? = null

    var orderNumber: Int? = null

    /**
     * 权限代码
     */
    var authorityCode: String? = null

    @Column(name = "[describe]")
    var describe: String? = null

    companion object{
        enum class Type{
            DIRECTORY,
            MENU,
            BUTTON
        }
    }
}